package com.activemq.cluster;

import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

@Slf4j
public class ClusterRev {
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ClusterProd.CLUSTER_URL);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(ClusterProd.QUEUE_NAME);
        MessageConsumer consumer = session.createConsumer(queue);
        consumer.setMessageListener((message) -> {
            try {
                System.out.println(((TextMessage) message).getText());
            } catch (JMSException e) {
                log.error("出错", e);
            }
        });
        System.in.read();
        consumer.close();
        session.close();
        connection.close();
    }
}
